class Solution
{
public:
    void rotate(vector<int> &nums, int k)
    {
        int n = nums.size();
        k = k % n;
        vector<int> lastKNums(nums.end() - k, nums.end());
        for (int i = n - 1; i >= k; --i)
        {
            nums[i] = nums[i - k];
        }
        for (int i = 0; i < k; ++i)
        {
            nums[i] = lastKNums[i];
        }
    }
};